/**
 * 枚举类的两种定义方法和三种常用方法
 * 定义方法一:普通的Class定义方法
 * 定义方法二:用enum关键字定义
 * 三个常用方法:
 * values
 * valueOf
 * toString
 *
 * @author wx
 * @create 2019-12-13 16:23
 */
public class enumDemo {
    public static void main(String[] args) {
        //不重写的话调用父类Object的toString方法,
        System.out.println(Season.SPRING);
        //枚举类的父类
        System.out.println(SeasonEnum.class.getSuperclass());
        //toString不重写的话默认输出父类Enum的name属性
        //需要的话重写即可
        System.out.println(SeasonEnum.SPRING);
        //values方法返回该枚举类的对象数组
        for (SeasonEnum seasonEnum : SeasonEnum.values()) {
            System.out.println("seasonEnum.name() = " + seasonEnum.name());
        }
        //valueOf返回按名字(name属性)查到的对象
        System.out.println("SeasonEnum.valueOf(\"SPRING\") = " + SeasonEnum.valueOf("SPRING"));
        //错误的情况下会抛异常IllegalArgumentException
//        System.out.println("SeasonEnum.valueOf(\"SPRING1\") = " + SeasonEnum.valueOf("SPRING1"));

        System.out.println("\"8615760388204\".substring(2) = " + "8615760388204".substring(2));
    }
}


//普通枚举类的定义方法
class Season {
    //1.如果枚举类对象有属性的话,需要定义为私有final的
    private final String seasonName;
    private final String seasonDesc;

    //2.枚举类的构造方法也必须是私有的,限制枚举类对象的个数
    private Season(String seasonName, String seasonDesc) {

        this.seasonName = seasonName;
        this.seasonDesc = seasonDesc;
    }

    //3.枚举类的具体对象,有限个
    public static final Season SPRING = new Season("春天", "四季如春");
    public static final Season SUMMER = new Season("夏天", "夏日炎炎");
    public static final Season AUTOMN = new Season("秋天", "秋高气爽");
    public static final Season WINTER = new Season("冬天", "冰天雪地");

    @Override
    public String toString() {
        return "Season{" +
                "seasonName='" + seasonName + '\'' +
                ", seasonDesc='" + seasonDesc + '\'' +
                '}';
    }
}
//用enum关键字创建的枚举类
enum SeasonEnum {
    //具体的枚举对象要写在最前面
    //并且也不用new对象，直接按照下面的写法写就行！
    //类与类之间用逗号分隔，最后一个用分号
    SPRING("春", "四季如春enum"),
    SUMMER("夏", "夏日炎炎enum"),
    AUTOMN("秋", "秋高气爽enum"),
    WINTER("冬", "冰天雪地enum");


    @Override
    public String toString() {
        return "SeasonEnum{" +
                "seasonName='" + seasonName + '\'' +
                ", seasonDesc='" + seasonDesc + '\'' +
                '}';
    }

    private final String seasonName;
    private final String seasonDesc;


    private SeasonEnum(String seasonName, String seasonDesc) {

        this.seasonName = seasonName;
        this.seasonDesc = seasonDesc;
    }

}
//不带属性的枚举类，就这么简单
enum  SeasonEnumSimple{
    SPRING,
    SUMMER,
    WINTER,
    AUTOMN;
}